cmake_minimum_required(VERSION 3.14)
project(g1_hand_bridge LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# SDK include paths
include_directories(${CMAKE_SOURCE_DIR}/../unitree_sdk2/include)
include_directories(${CMAKE_SOURCE_DIR}/../unitree_sdk2/thirdparty/include)
include_directories(${CMAKE_SOURCE_DIR}/../unitree_sdk2/thirdparty/include/ddscxx)

add_executable(g1_hand_bridge src/g1_hand_bridge.cpp)

# Link CycloneDDS C/C++ libs shipped with SDK
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
  set(UNITREE_THIRDPARTY_LIB_DIR ${CMAKE_SOURCE_DIR}/../unitree_sdk2/thirdparty/lib/x86_64)
  set(UNITREE_SDK_LIB_DIR       ${CMAKE_SOURCE_DIR}/../unitree_sdk2/lib/x86_64)
else()
  set(UNITREE_THIRDPARTY_LIB_DIR ${CMAKE_SOURCE_DIR}/../unitree_sdk2/thirdparty/lib/aarch64)
  set(UNITREE_SDK_LIB_DIR       ${CMAKE_SOURCE_DIR}/../unitree_sdk2/lib/aarch64)
endif()
link_directories(${UNITREE_THIRDPARTY_LIB_DIR})
link_directories(${UNITREE_SDK_LIB_DIR})

#target_link_libraries(g1_hand_bridge PRIVATE unitree_sdk2 ddscxx ddsc)
#chen kaixuan target_link_libraries
target_link_libraries(g1_hand_bridge PRIVATE
    ${UNITREE_SDK_LIB_DIR}/libunitree_sdk2.a
    ${UNITREE_THIRDPARTY_LIB_DIR}/libddscxx.so
    ${UNITREE_THIRDPARTY_LIB_DIR}/libddsc.so
    pthread
    dl
)
if(UNIX)
  target_link_libraries(g1_hand_bridge PRIVATE pthread dl)
endif()

# Set rpath so the executable can find ddscxx/ddsc at runtime
set_target_properties(g1_hand_bridge PROPERTIES
  BUILD_WITH_INSTALL_RPATH TRUE
  INSTALL_RPATH ${UNITREE_THIRDPARTY_LIB_DIR}
  SKIP_BUILD_RPATH FALSE
  BUILD_RPATH ${UNITREE_THIRDPARTY_LIB_DIR}
)


